package com.zhentao.controller;

import com.zhentao.file.server.FileStorageService;
import com.zhentao.model.common.dtos.ResponseResult;
import com.zhentao.service.ApArticleContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.FileInputStream;
import java.io.FileNotFoundException;

@RestController
@RequestMapping("minio")
public class MinioTestController {
    @Autowired
    private FileStorageService fileStorageService;
    @Autowired
    private ApArticleContentService apArticleContentService;

    @RequestMapping("/uploadHtml")
    public ResponseResult uploadHtml() throws FileNotFoundException {

        FileInputStream fileInputStream=new FileInputStream("E:\\freemarker\\test\\03.html");
        try {
            String url = fileStorageService.uploadHtmlFile("03.html", fileInputStream);
            return ResponseResult.okResult(url);
        }catch (Exception e){
            return ResponseResult.errorResult(303,"minio异常");
        }
    }

    @RequestMapping("upHtml")
    public ResponseResult upHtml(Long id){
        return apArticleContentService.createStaticUrl(id);
    }
}
